﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Input;

namespace BaiDuYunAddSpeed.Tool
{
    public  class TheMouseStyle
    {
         /*光标资源加载函数
         * fileName为加载路径下的.cur文件
         */
        [DllImport("User32.DLL")]
        public static extern IntPtr LoadCursorFromFile(string fileName);

        /*设置系统指针函数（用hcur替换id定义的光标）
         * hcur用于表示指针或句柄的特定类型，可以用LoadCursorFromFile函数加载一个路径下的.cur指针文件
         * id是系统光标标识符，例：
         * OCR_APPSTARTING：标准箭头和小的沙漏；
         * OCR_NORAAC：标准箭头；
         * OCR_CROSS：交叉十字线光标；
         * OCR_HAND：手的形状（WindowsNT5.0和以后版本）；
         * OCR_HELP：箭头和向东标记；
         * OCR_IBEAM：I形梁；
         * OCR_NO：斜的圆；
         * OCR_SIZEALL：四个方位的箭头分别指向北、南、东、西；
         * OCR_SIZENESEW：双箭头分别指向东北和西南；
         * OCR_SIZENS：双箭头，分别指向北和南；
         * OCR_SIZENWSE：双箭头分别指向西北和东南；
         * OCR_SIZEWE：双箭头分别指向西和东；
        */
        [DllImport("User32.DLL")]
        public static extern bool SetSystemCursor(IntPtr hcur, uint id);
        /// <summary>
        /// 标准箭头
        /// </summary>
        public const uint OCR_NORMAL = 32512;
        /// <summary>
        /// 标准箭头和小沙漏
        /// </summary>
        public const uint OCR_APPSTARTING = 32650;
        public const uint OCR_WAIT = 32514;
        public const uint OCR_CROSS = 32515;
        public const uint OCR_HAND = 32649;
        public const uint OCR_HELP = 32651;
        public const uint OCR_IBEAM = 32513;
        public const uint OCR_NO = 32648;
        public const uint OCR_SIZEALL = 32646;
        public const uint OCR_SIZENESW = 32643;
        public const uint OCR_SIZENS = 32645;
        public const uint OCR_SIZENWSE = 32642;
        public const uint OCR_SIZEWE = 32644;
        public const uint OCR_UP = 32516;

        /*查询或设置的系统级参数函数
         * uiAction该参数指定要查询或设置的系统级参数，SPI_SETCURSORS：重置系统光标
         * fWinIni该参数指定在更新用户配置文件之后广播SPI_SENDWININICHANGE消息
         */
        [DllImport("User32.DLL")]
        public static extern bool SystemParametersInfo(uint uiAction, uint uiParam, IntPtr pvParam, uint fWinIni);
        public const uint SPI_SETCURSORS = 87;
        public const uint SPIF_SENDWININICHANGE = 2;

        public static void Change() 
        {
            //原图
            Bitmap cursorBmp = Resource1.ai5g2_7moqm_001.ToBitmap();
            //自定义大小(缩小一倍)；
            Bitmap bmp = new Bitmap(cursorBmp, cursorBmp.Width / 10, cursorBmp.Height / 10);
            //正常状态图标
            SetSystemCursor(bmp.GetHicon(), OCR_APPSTARTING);
            SetSystemCursor(bmp.GetHicon(), OCR_WAIT);
            SetSystemCursor(bmp.GetHicon(), OCR_CROSS);
            SetSystemCursor(bmp.GetHicon(), OCR_HAND);
            SetSystemCursor(bmp.GetHicon(), OCR_HELP);
            SetSystemCursor(bmp.GetHicon(), OCR_IBEAM);
            SetSystemCursor(bmp.GetHicon(), OCR_NO);
            SetSystemCursor(bmp.GetHicon(), OCR_SIZEALL);
            SetSystemCursor(bmp.GetHicon(), OCR_SIZENESW);
            SetSystemCursor(bmp.GetHicon(), OCR_SIZENS);
            SetSystemCursor(bmp.GetHicon(), OCR_SIZENWSE);
            SetSystemCursor(bmp.GetHicon(), OCR_SIZEWE);
            SetSystemCursor(bmp.GetHicon(), OCR_UP);
            SetSystemCursor(bmp.GetHicon(), OCR_NORMAL);
        }
        
        public static void OnApplicationQuit()
        {
            //恢复为系统默认图标
            SystemParametersInfo(SPI_SETCURSORS, 0, IntPtr.Zero, SPIF_SENDWININICHANGE);
        }
    }
}
